﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Collections;

namespace XCommunity.Documents
{
  /// <summary>
  /// 代表一个文档，文档是发布信息的最小单位，一次只能发布一个文档，所有发布的信息都必须以文档的形式存在
  /// </summary>
  public abstract class Document
  {


    private DocumentMeta _meta;

    protected Document( DocumentMeta meta )
    {
      _meta = meta;
    }

    /// <summary>
    /// 文档的元数据
    /// </summary>
    public DocumentMeta Meta
    {
      get { return _meta; }
    }


    /// <summary>
    /// 将文档内容保存到一个流中
    /// </summary>
    /// <param name="stream">文档保存流</param>
    public abstract void SaveDocument( Stream stream );

    /// <summary>
    /// 从流中读取一个文档
    /// </summary>
    /// <param name="stream">文档读取流</param>
    public abstract void LoadDocument( Stream stream );

    /// <summary>
    /// 指示该文档是否已经被加载
    /// </summary>
    public abstract bool Loaded
    {
      get;
    }

    /// <summary>
    /// 文档类型
    /// </summary>
    public virtual String DocumentType
    {
      get
      {
        return GetType().AssemblyQualifiedName;
      }
    }

    
    
    
    
    
    Hashtable _metaDictionary = new Hashtable();

    public object this[object key]
    {
      get
      {
        lock ( _metaDictionary.SyncRoot )
        {
          return _metaDictionary[key];
        }
      }
      set
      {
        lock ( _metaDictionary.SyncRoot )
        {
          _metaDictionary[key] = value;
        }
      }
    }

  }
}
